#!/usr/bin/env python
#coding=utf-8
# author:wade
# contact: 317909531@qq.com
# datetime:2020/9/26 11:32
from rest_framework import serializers

from BookContent import models

"""
文件说明：
"""

# 获取所有当前所有的分类列表(嵌套不支持直接反序列化)
class B_Type_serializers_bookContent(serializers.ModelSerializer):
    def to_representation(self, instance):  #对于空值进行处理，防止给前端的是null
        data = super().to_representation(instance)
        # print(data)
        for i in data :
            if not data[i] and data[i] != 0:
                print(data[i])
                data[i] = ""
        return data
    class Meta:
        model = models.Type
        fields = '__all__'
        # fields = ['CLASS_NUM', 'ID']
        depth = 3
# 获取所有当前某个分类下的标题和内容
class B_XXXTypeList_serializers_bookContent(serializers.ModelSerializer):
    def to_representation(self, instance):  #对于空值进行处理，防止给前端的是null
        data = super().to_representation(instance)
        # print(data)
        for i in data:
            if not data[i] and data[i] != 0:
                print(data[i])
                data[i] = ""
        return data
    class Meta:
        model = models.BookPageContent
        # fields = '__all__'
        fields = ['ID', 'Title', 'clickNum', 'Img','TypeTitle','IntroWord']
        depth = 3